package com.visizen.wisdomclass.server.client;

import com.visizen.wisdomclass.server.model.WcOrganization;
import com.visizen.wisdomclass.server.model.WcOrganizationExample;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface WcOrganizationMapper {
    //通过班级id查询班级的信息，包括查找出班级的年级
    @Select("SELECT * FROM wc_organization WHERE organization_id=#{classId} and category_id=3")
    @Results({
            @Result(property = "parent", column = "parent_organization_id", one = @One(select = "getGradeInfoByGradeId"))
    })
    WcOrganization getClassInfoByClassId(@Param("classId") long classId);

    //通过年级ID查询出年级的信息，包括查找出班级的学校
    @Select("SELECT * FROM wc_organization WHERE organization_id=#{gradeId} and category_id=2")
    @Results({
            @Result(property = "parent", column = "parent_organization_id", one = @One(select = "getSchoolInfoBySchoolId"))
    })
    WcOrganization getGradeInfoByGradeId(@Param("gradeId") long gradeId);

    //通过学校ID查询学校的信息
    @Select("SELECT * FROM wc_organization WHERE organization_id=#{schoolId}")
    WcOrganization getSchoolInfoBySchoolId(@Param("schoolId") long schoolId);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_organization
     *
     * @mbggenerated
     */
    @SelectProvider(type = WcOrganizationSqlProvider.class, method = "countByExample")
    int countByExample(WcOrganizationExample example);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_organization
     *
     * @mbggenerated
     */
    @DeleteProvider(type = WcOrganizationSqlProvider.class, method = "deleteByExample")
    int deleteByExample(WcOrganizationExample example);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_organization
     *
     * @mbggenerated
     */
    @Delete({"delete from wc_organization",
            "where organization_id = #{organization_id,jdbcType=BIGINT}"})
    int deleteByPrimaryKey(Long organization_id);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_organization
     *
     * @mbggenerated
     */
    @Insert({
            "insert into wc_organization (organization_id, parent_organization_id, ",
            "category_id, NAME, ",
            "desc)",
            "values (#{organization_id,jdbcType=BIGINT}, #{parent_organization_id,jdbcType=BIGINT}, ",
            "#{category_id,jdbcType=BIGINT}, #{NAME,jdbcType=VARCHAR}, ",
            "#{desc,jdbcType=LONGVARCHAR})"})
    int insert(WcOrganization record);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_organization
     *
     * @mbggenerated
     */
    @InsertProvider(type = WcOrganizationSqlProvider.class, method = "insertSelective")
    int insertSelective(WcOrganization record);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_organization
     *
     * @mbggenerated
     */
    @SelectProvider(type = WcOrganizationSqlProvider.class, method = "selectByExampleWithBLOBs")
    @Results({
            @Result(column = "organization_id", property = "organization_id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "parent_organization_id", property = "parent_organization_id", jdbcType = JdbcType.BIGINT),
            @Result(column = "category_id", property = "category_id", jdbcType = JdbcType.BIGINT),
            @Result(column = "NAME", property = "NAME", jdbcType = JdbcType.VARCHAR),
            @Result(column = "desc", property = "desc", jdbcType = JdbcType.LONGVARCHAR)})
    List<WcOrganization> selectByExampleWithBLOBs(WcOrganizationExample example);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_organization
     *
     * @mbggenerated
     */
    @SelectProvider(type = WcOrganizationSqlProvider.class, method = "selectByExample")
    @Results({
            @Result(column = "organization_id", property = "organization_id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "parent_organization_id", property = "parent_organization_id", jdbcType = JdbcType.BIGINT),
            @Result(column = "category_id", property = "category_id", jdbcType = JdbcType.BIGINT),
            @Result(column = "NAME", property = "NAME", jdbcType = JdbcType.VARCHAR)})
    List<WcOrganization> selectByExample(WcOrganizationExample example);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_organization
     *
     * @mbggenerated
     */
    @Select({"select",
            "organization_id, parent_organization_id, category_id, NAME, desc",
            "from wc_organization",
            "where organization_id = #{organization_id,jdbcType=BIGINT}"})
    @Results({
            @Result(column = "organization_id", property = "organization_id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "parent_organization_id", property = "parent_organization_id", jdbcType = JdbcType.BIGINT),
            @Result(column = "category_id", property = "category_id", jdbcType = JdbcType.BIGINT),
            @Result(column = "NAME", property = "NAME", jdbcType = JdbcType.VARCHAR),
            @Result(column = "desc", property = "desc", jdbcType = JdbcType.LONGVARCHAR)})
    WcOrganization selectByPrimaryKey(Long organization_id);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_organization
     *
     * @mbggenerated
     */
    @UpdateProvider(type = WcOrganizationSqlProvider.class, method = "updateByExampleSelective")
    int updateByExampleSelective(@Param("record") WcOrganization record,
                                 @Param("example") WcOrganizationExample example);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_organization
     *
     * @mbggenerated
     */
    @UpdateProvider(type = WcOrganizationSqlProvider.class, method = "updateByExampleWithBLOBs")
    int updateByExampleWithBLOBs(@Param("record") WcOrganization record,
                                 @Param("example") WcOrganizationExample example);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_organization
     *
     * @mbggenerated
     */
    @UpdateProvider(type = WcOrganizationSqlProvider.class, method = "updateByExample")
    int updateByExample(@Param("record") WcOrganization record,
                        @Param("example") WcOrganizationExample example);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_organization
     *
     * @mbggenerated
     */
    @UpdateProvider(type = WcOrganizationSqlProvider.class, method = "updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(WcOrganization record);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_organization
     *
     * @mbggenerated
     */
    @Update({
            "update wc_organization",
            "set parent_organization_id = #{parent_organization_id,jdbcType=BIGINT},",
            "category_id = #{category_id,jdbcType=BIGINT},",
            "NAME = #{NAME,jdbcType=VARCHAR},",
            "desc = #{desc,jdbcType=LONGVARCHAR}",
            "where organization_id = #{organization_id,jdbcType=BIGINT}"})
    int updateByPrimaryKeyWithBLOBs(WcOrganization record);

    /**
     * This method was generated by MyBatis Generator. This method corresponds to the database table wc_organization
     *
     * @mbggenerated
     */
    @Update({
            "update wc_organization",
            "set parent_organization_id = #{parent_organization_id,jdbcType=BIGINT},",
            "category_id = #{category_id,jdbcType=BIGINT},",
            "NAME = #{NAME,jdbcType=VARCHAR}",
            "where organization_id = #{organization_id,jdbcType=BIGINT}"})
    int updateByPrimaryKey(WcOrganization record);
}